
package com.rt.schedulenew.utils.util;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import org.quartz.CronExpression;
import java.util.Date;
public class CronUtil
{
    public static String parseCron(final String cron) {
        final Date curTime = new Date();
        CronExpression expression = null;
        try {
            expression = new CronExpression(cron);
        }
        catch (ParseException e) {
            e.printStackTrace();
        }
        final Date newDate = expression.getNextValidTimeAfter(curTime);
        final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return formatter.format(newDate);
    }
    
    public static String formatCron(final int minute) {
        final Calendar c = Calendar.getInstance();
        c.set(Calendar.MINUTE, minute);
        final DateFormat formatter = new SimpleDateFormat("0 0/m * * * ?");
        return formatter.format(c.getTime());
    }
    
    public static void main(final String[] args) {
        System.out.println(formatCron(59));
        System.out.println(formatCron(60));
    }
}
